package com.entrogy.utils;


import org.redisson.Redisson;
import org.redisson.config.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class RedissonManager {

    private static final Logger logger = LoggerFactory.getLogger(RedissonManager.class);
    @Value("${redis.host}")
    private String host1;
    @Value("${redis.port}")
    private int port1;
    private Redisson redisson = null;
    private Config config = new Config();

//    private static String host1 = PropertiesUtil.getProperty("redis1.host");
//    private static int port1 = Integer.parseInt(PropertiesUtil.getProperty("redis1.port"));
//    private static String host2 = PropertiesUtil.getProperty("redis2.host");
//    private static int port2 = Integer.parseInt(PropertiesUtil.getProperty("redis2.port"));

    @PostConstruct
    private void init() {
        try {
            config.useSingleServer().setAddress(new StringBuilder().append(host1).append(":").append(port1).toString());

            redisson = (Redisson) Redisson.create(config);
            logger.info("================Redisson初始化完成================");
        } catch (Exception e) {
            logger.error("init Redisson error ",e);
        }
    }

    public Redisson getRedisson() {
        return redisson;
    }
}